<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="949.35">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #c50000}
span.s1 {color: #0000c1}
span.s2 {color: #000000}
span.s3 {color: #007500}
span.s4 {color: #606060}
span.s5 {color: #c50000}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><b>PV_BinDelay<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>Delay and Feedback on a bin by bin basis</b></p>
<p class="p2"><br></p>
<p class="p3"><b>PV_BinDelay(buffer, maxdelay, delaybuf, fbbuf, hop = 0.5)</b></p>
<p class="p4"><br></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>buffer - the FFT buffer.</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>maxdelay - in seconds. Used at init time to create memory for the delays. Non-modulatable.</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>delaybuf - a buffer of (fft buffer size / 2) containing the delay times for each bin. Delay times</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>will be rounded to the closest bin. Smaller FFT windows will yield better time resolution.</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>fbbuf - a buffer of (fft buffer size / 2) containing the fb percentages for each bin.</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>hop - if you are using FFT with a hop value different then the default 0.5, you need to tell PV_BinDelay</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>so it can calculate the correct times.</b></p>
<p class="p2"><br></p>
<p class="p3"><b>WARNING! This UGen needs to allocate a large amount of real-time memory at the outset (approx.</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>SampleRate * maxDelayTime). This will cause a CPU spike at startup. Also, due to memory</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>mangement restrictions, There is a limited number of previous frames that can be stored. Right now</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>no more the 512 frames can be stored. With a frame size of 512 samples, this makes a hard limit</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>to the max delay of about 5.9 seconds at a SR of 44100 (or (FFT size * 512) / SR). Chances are,</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>however, that you will run out of RT memory (the memSize ServerOption) before hitting these<span class="Apple-converted-space"> </span></b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>limits, especially at larger FFT frame sizes.</b></p>
<p class="p4"><br></p>
<p class="p3"><b>Examples:</b></p>
<p class="p2"><br></p>
<p class="p5">s.boot;</p>
<p class="p2"><br></p>
<p class="p5">(<span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="s1">Routine</span>.run({<span class="Apple-tab-span">	</span></p>
<p class="p6"><span class="s2"><span class="Apple-tab-span">	</span></span>// use as multislider - del time vals on top, feedback on the bottom</p>
<p class="p6"><span class="s2"><span class="Apple-tab-span">	</span></span>// max delay time is 1 second, delaytime and fb are initialized to 0.0</p>
<p class="p6"><span class="s2"><span class="Apple-tab-span">	</span></span>// and are controlled by the GUI. The multi-slider on the top controls<span class="Apple-converted-space"> </span></p>
<p class="p6"><span class="s2"><span class="Apple-tab-span">	</span></span>// each bins delay time, the bottom controls FB.</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s1">var</span> size, awin, bsl, car, dar, fsl, maxdel, synth, cond;</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="Apple-tab-span">	</span>size = 128;</p>
<p class="p5"><span class="Apple-tab-span">	</span>maxdel = 0.5;</p>
<p class="p5"><span class="Apple-tab-span">	</span>cond = <span class="s1">Condition</span>.new;</p>
<p class="p5"><span class="Apple-tab-span">	</span>s.sendMsg(<span class="s3">\b_alloc</span>, b=s.bufferAllocator.alloc(1), size * 2);</p>
<p class="p5"><span class="Apple-tab-span">	</span>s.sendMsg(<span class="s3">\b_alloc</span>, c=s.bufferAllocator.alloc(1), size);</p>
<p class="p5"><span class="Apple-tab-span">	</span>s.sendMsg(<span class="s3">\b_alloc</span>, d=s.bufferAllocator.alloc(1), size);</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="Apple-tab-span">	</span>y = <span class="s1">Array</span>.fill(size, {0.0});</p>
<p class="p5"><span class="Apple-tab-span">	</span>s.sendBundle(0.1, [<span class="s3">\b_setn</span>, d, 0, size] ++ y);</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="Apple-tab-span">	</span>z = <span class="s1">Array</span>.fill(size, {<span class="s1">arg</span> i; 0.0});</p>
<p class="p5"><span class="Apple-tab-span">	</span>s.sendBundle(0.1, [<span class="s3">\b_setn</span>, c, 0, size] ++ z);</p>
<p class="p5"><span class="Apple-tab-span">	</span>s.sync(cond);</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="Apple-tab-span">	</span>synth = <span class="s1">SynthDef</span>(<span class="s4">"help-noopFFT"</span>, { <span class="s1">arg</span> inbus,out=0,bufnum=0, dels=0, fb=0;</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s1">var</span> in, chain;</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>in = <span class="s1">Impulse</span>.ar(0.33);</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>in = PlayBuf.ar(1, playbuf, loop: 1);</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>chain = <span class="s1">FFT</span>(bufnum, in, 0.25);</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>chain = <span class="s1">PV_BinDelay</span>(chain, maxdel, dels, fb, 0.25);</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s1">Out</span>.ar(out,<span class="Apple-converted-space"> </span></p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>in + <span class="s1">IFFT</span>(chain) <span class="s5">// inverse FFT</span></p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>);</p>
<p class="p5"><span class="Apple-tab-span">	</span>}).play(s,[<span class="s3">\out</span>,0,<span class="s3">\bufnum</span>,b,<span class="s3">\dels</span>, c, <span class="s3">\fb</span>, d, <span class="s3">\inbus</span>, s.options.numOutputBusChannels]);</p>
<p class="p5"><span class="Apple-tab-span">	</span>{</p>
<p class="p5"><span class="Apple-tab-span">	</span>awin = <span class="s1">GUI</span>.window.new(<span class="s4">"test"</span>, <span class="s1">Rect</span>(200 , 450, 10 + (size * 1), 10 + (size * 2)));</p>
<p class="p5"><span class="Apple-tab-span">	</span>awin.view.decorator =<span class="Apple-converted-space">  </span><span class="s1">FlowLayout</span>(awin.view.bounds);</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="Apple-tab-span">	</span>bsl = <span class="s1">GUI</span>.multiSliderView.new(awin, <span class="s1">Rect</span>(0, 0, size * 1, size * 1));</p>
<p class="p5"><span class="Apple-tab-span">	</span>bsl.action = {<span class="s1">arg</span> xb; (<span class="s4">"Deltime index: "</span> ++ xb.index ++<span class="s4">" value: "</span> ++<span class="Apple-converted-space"> </span></p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>(xb.currentvalue * maxdel)).postln;</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>s.sendMsg(<span class="s3">\b_set</span>, c, xb.index, xb.currentvalue * maxdel);</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>};</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="Apple-tab-span">	</span>fsl = <span class="s1">GUI</span>.multiSliderView.new(awin, <span class="s1">Rect</span>(0, 0, size * 1, size * 1));</p>
<p class="p5"><span class="Apple-tab-span">	</span>fsl.action = {<span class="s1">arg</span> xb; (<span class="s4">"FB index: "</span> ++ xb.index ++<span class="s4">" value: "</span> ++ xb.currentvalue).postln;</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>s.sendMsg(<span class="s3">\b_set</span>, d, xb.index, xb.currentvalue);</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>};</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="Apple-tab-span">	</span>car = <span class="s1">Array</span>.new;</p>
<p class="p5"><span class="Apple-tab-span">	</span>size.do({<span class="s1">arg</span> i;</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>car = car.add(0);</p>
<p class="p5"><span class="Apple-tab-span">	</span>});</p>
<p class="p5"><span class="Apple-tab-span">	</span>bsl.value_(car);</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="Apple-tab-span">	</span>dar = <span class="s1">Array</span>.new;</p>
<p class="p5"><span class="Apple-tab-span">	</span>size.do({<span class="s1">arg</span> i;</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>dar = dar.add(0);</p>
<p class="p5"><span class="Apple-tab-span">	</span>});</p>
<p class="p5"><span class="Apple-tab-span">	</span>fsl.value_(car);</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="Apple-tab-span">	</span>bsl.xOffset_(5);</p>
<p class="p5"><span class="Apple-tab-span">	</span>bsl.thumbSize_(12.0);</p>
<p class="p5"><span class="Apple-tab-span">	</span>fsl.xOffset_(5);</p>
<p class="p5"><span class="Apple-tab-span">	</span>fsl.thumbSize_(12.0);</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p6"><span class="s2"><span class="Apple-tab-span">	</span></span>// value axis size of each blip in pixels</p>
<p class="p5"><span class="Apple-tab-span">	</span>bsl.valueThumbSize_(15.0);</p>
<p class="p6"><span class="s2"><span class="Apple-tab-span">	</span></span>// index axis size of each blip in pixels</p>
<p class="p5"><span class="Apple-tab-span">	</span>bsl.indexThumbSize_( bsl.bounds.width / car.size );</p>
<p class="p5"><span class="Apple-tab-span">	</span>bsl.gap = 0;</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p6"><span class="s2"><span class="Apple-tab-span">	</span></span>// value axis size of each blip in pixels</p>
<p class="p5"><span class="Apple-tab-span">	</span>fsl.valueThumbSize_(15.0);</p>
<p class="p6"><span class="s2"><span class="Apple-tab-span">	</span></span>// index axis size of each blip in pixels</p>
<p class="p5"><span class="Apple-tab-span">	</span>fsl.indexThumbSize_( fsl.bounds.width / dar.size );</p>
<p class="p5"><span class="Apple-tab-span">	</span>fsl.gap = 0;</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="Apple-tab-span">	</span>awin.front;</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p5"><span class="Apple-tab-span">	</span>awin.onClose_({</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>synth.free;</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>s.sendMsg(<span class="s3">\b_free</span>, b);</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>s.sendMsg(<span class="s3">\b_free</span>, c);</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>s.sendMsg(<span class="s3">\b_free</span>, d);</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>})</p>
<p class="p5"><span class="Apple-tab-span">	</span>}.defer;</p>
<p class="p5"><span class="Apple-tab-span">	</span>})</p>
<p class="p5">)</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
</body>
</html>
